﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace ZYing.QPanel.Converters
{
    public class SingleLineStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return string.Empty;
            if (value is string str && !string.IsNullOrWhiteSpace(str))
            {
                str= str.Replace('\n', ' ').Replace('\r', ' ');
                if (str.Length > 200) str = str.Substring(200);
                return str;
            }
            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
